import axios from '@/utils/axios';

const state = {
  companyList: []
};
const mutations = {
  SET_COMPANY_LIST: (state: any, list: any) => {
    state.companyList = list;
  }
};
const actions = {
  // 获取公证处(注册时候使用)
  async getList({ commit }) {
    const { data } = await axios({
      url: '/api/company/list',
      method: 'get'
    });
    commit('SET_COMPANY_LIST', data)
    return data;
  },
  // 获取公证处（公证处管理使用）
  async getManageList({ commit }) {
    const { data } = await axios({
      url: '/api/company/manage/list',
      method: 'get'
    });
    return data;
  },
  // 添加公证处
  async addCompany({ commit }, params) {
    const { data } = await axios({
      url: '/api/company/add',
      method: 'post',
      data: params
    });
  },
  // 修改公证处
  async updateCompany({ commit }, params) {
    const { data } = await axios({
      url: '/api/company/update',
      method: 'post',
      data: params
    });
  },
  // 删除公证处
  async delCompany({ commit }, params) {
    const { data } = await axios({
      url: '/api/company/del',
      method: 'delete',
      data: params
    });
  },
  // 获取某个城市的公证处 
  async getCompanyWithCity({ commit }, params) {
    const { data } = await axios({
      url: '/api/company/withCity',
      method: 'get',
      params
    });
    return data;
  },
  // 获取我的公证处 
  async getCompanyMine({ commit }, params) {
    const { data } = await axios({
      url: '/api/company/mine',
      method: 'get',
      params
    });
    return data;
  }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
  };
  